var currPage = 1;
var dataDetail=null;
;layui.define(function(e) {
    layui.use(['table','layer','form','laydate'], function(){
         var $ = layui.$
            ,layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate;
         
         //页面初始化加载数据
         table.render({
             elem: '#tableId'
             ,url: hostUrl + '/purchaseIntentioOrderHead/dealerCarSourcelist'
             ,cols: [[ //标题栏
             	 {field: 'brand_name', title: '品牌'}
                 ,{field: 'series_name', title: '车系'}
                 ,{field: 'car_type_name', title: '车型'}
                 ,{field: 'factory_price', title: '指导价(万元)'}
                 ,{field: 'batch_sale_price', title: '采购价(万元)'} //经销商的采购价=平台的批售价
                 ,{field: 'pay_type_name', title: '支付方式'}
                 ,{field: 'arrive_days', title: '到货周期'}
                 ,{field: 'start_amount', title: '起订数量'}
                 ,{field: 'stock_amount', title: '库存数量'}
                 ,{title: '操作', width:180, align:'center', toolbar: '#barDemo',fixed: 'right'}
             ]]
         	,id: 'listReload'
             ,page: true //是否显示分页
         });
        
       //表刷新方法    查询方法调用
        var reloadTable = function (page) {
            var length = arguments.length;   //  实际传入参数的长度
            if (length == 0) {
                page = 1;
            }
            table.reload("listReload", { //此处是上文提到的 初始化标识id
                where: {
                    "brandOrSeriesOrTypeName": $("#brandOrSeriesOrTypeName").val(),
                    "start_amount": $("#start_amount").val(),
                    "seriesName": $("#seriesName").val(),
                    "area_id": $("#area_id").val()
                }, page: {
                    curr: page //重新从第 page 页开始 默认从第一页开始重载
                }
            });
        };
       //查询按钮绑定点击事件
        $("#searchBtn").on("click", function () {
            reloadTable();
        })
        
        
        //监听工具条
        table.on('tool(listTable)', function(obj){
            var data = obj.data;
          if(obj.event === 'detail'){
            	dataDetail = data;
            	dataDetail["purchase_price"]=dataDetail.batch_sale_price;
            	var detail=layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '车源详情'
                    ,content:'info.do'
                    ,area: ['800px', '600px']
                    ,maxmin: true
                    ,success: function(layero, index) {
                    	
                    }
                    ,end: function(){
                    	dataDetail=null;
                    }
                }); 
            	layer.full(detail); 
            }
        });
        form.render();
        
        //下意向单
        $("#inputIntendedOrder").click(function () {
            var index = layer.open({
                type: 2
                ,id: (new Date()).valueOf()
                ,title: '下意向单'
                ,content: hostUrl+'/dealercarsource/inputIntentioOrder.do' //跳转路径
                ,area: ['500px', '500px']
//                ,btn: ['下订', '取消']
                ,maxmin: true
                ,success: function(layero, index){
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    //                    console.log(body.html()) //得到iframe页的body内容
                }
                ,yes: function(index, layero){
                    //发布【按钮一】的回调
                }
                ,btn2: function(index, layero){
                    //取消【按钮三】的回调
                    alert("取消")
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
            layer.full(index);
        });
    });
    //输出模块
    e("carInquire", {})
});